<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>调拨接收编辑</title>
<!-- import css and js -->
<%@ include file="/common/metaInput.jsp"%>
<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
<script type="text/javascript" src="${ctx}/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="${ctx}/js/jsp/yd/logic/ItemStateData.js"></script>
<script src="${ctx}/js/jsp/date.js" type="text/javascript"></script>
<script type="text/javascript">
	var basic_Url = "${ctx}/logic/allocatinwh";
	var addressGrid;
	$(function(){
		//单据状态
		var billSt = '${inwh.zd002Status}';
		var column1 = [{ display: 'id', name: 'id',type: 'string',hide : true},
	    			   { display: 'zd002MaterId', name: 'zd002MaterId',hide : true},
	    			   { display: '<font color="gray">编码</font>', name: 'zd003Code',width: 100},
	    			   { display: '<font color="gray">名称</font>', name: 'zd004Name',width: 100},
	    			   { display: '<font color="gray">类型</font>', name: 'zd005Type',width: 100},
	    			   { display: '<font color="gray">规格</font>', name: 'zd006Spec' ,width: 100},
	    			   { display: '<font color="gray">型号</font>', name: 'zd007Model' ,width: 100},
	    			   { display: '<font color="gray">颜色</font>', name: 'zd009Color' ,width: 100},
	    			   { display: '<font color="gray">材质</font>', name: 'zd010Quality' ,width: 100},
	    			   { display: '<font color="gray">大小</font>', name: 'zd011Size' ,width: 120},
	    			   { display: '<font color="gray">单位</font>', name: 'zd012Unit', width: 100 },
	    			   { display: '<font color="gray">单价</font>', name: 'zd014Price', width: 100 },
	    			   { display: '<font color="gray">含税单位</font>', name: 'zd015TaxPrice', width: 100 },
	    			   { display: '<font color="gray">调拨数量</font>', name: 'zd018OutQuantity',width: 100 },
	    			   { display: '<font color="gray">已接收数量</font>', name: 'zd020HasInQuantity',width: 100 },
	    			   { display: '<font color="gray">未接收数量</font>', name: 'zd021NoInQuantity',width: 100 },
					   { display: '本次接收数量<font color="red">*</font>', name: 'zd019InQuantity',width: 150,editor : {type :'float'},
	    				  render:function(item){
	                      	return (item.zd019InQuantity==undefined ? 0:(1*item.zd019InQuantity).toFixed(4));
	                   	  }
					   }];
		var column2 = [{ display: 'id', name: 'id',type: 'string',hide : true},
	    			   { display: 'zd002MaterId', name: 'zd002MaterId',hide : true},
	    			   { display: '<font color="gray">编码</font>', name: 'zd003Code',width: 100},
	    			   { display: '<font color="gray">名称</font>', name: 'zd004Name',width: 100},
	    			   { display: '<font color="gray">类型</font>', name: 'zd005Type',width: 100},
	    			   { display: '<font color="gray">规格</font>', name: 'zd006Spec' ,width: 100},
	    			   { display: '<font color="gray">型号</font>', name: 'zd007Model' ,width: 100},
	    			   { display: '<font color="gray">颜色</font>', name: 'zd009Color' ,width: 100},
	    			   { display: '<font color="gray">材质</font>', name: 'zd010Quality' ,width: 100},
	    			   { display: '<font color="gray">大小</font>', name: 'zd011Size' ,width: 120},
	    			   { display: '<font color="gray">单位</font>', name: 'zd012Unit', width: 100 },
	    			   { display: '<font color="gray">单价</font>', name: 'zd014Price', width: 100 },
	    			   { display: '<font color="gray">含税单位</font>', name: 'zd015TaxPrice', width: 100 },
	    			   { display: '<font color="gray">调拨数量</font>', name: 'zd018OutQuantity',width: 100 },
	    			   { display: '<font color="gray">已接收数量</font>', name: 'zd020HasInQuantity',width: 100 },
	    			   { display: '<font color="gray">未接收数量</font>', name: 'zd021NoInQuantity',width: 100 },
					   { display: '本次接收数量<font color="red">*</font>', name: 'zd019InQuantity',width: 150}
	    			   ];
		var column3 = column1;
		if(''==billSt && 'ADD'=='${flag}'){
			//新增
			column3 = column1;
		}else{
			if('INWH_SAVE'==billSt || 'INWH_BACK'==billSt){
				column3 = column1;
			}else{
				column3 = column2;
			}
		}
		addressGrid = $("#dataGrid1").ligerGrid({
        	columns: column3,
        	enabledEdit: true,
            usePager: true,pageSize:1000,pageSizeOptions:[1000],
            parms:[{ name : 'aocInwhId' , value : '${inwh.id}'}],
            url : basic_Url+"/gridItems.do",
            width: "100%", height:250, checkbox: true,rownumbers:true,
            toolbar: { items: [{ text: '删除', click: deleteRow, img: '${ctx}/js/ligerUI/skins/icons/delete.gif' }]}
        });
		$("#pageloading").hide();
		
		$("#zd001AllocatId").change(function(){ 
			if($("#zd001AllocatId").val()==""){
				 $.dialog.alert("调拨发起单号不能为空");
				 return false;
			}
			$("#zd001AllocatCode").val($("#zd001AllocatId").find("option:selected").text());
			var outwhId = $("#zd001AllocatId").find("option:selected").val();
			if(outwhId != ''){
				$.ajax({
	    		      url: basic_Url+"/getAclOutwh.do",
	    		      global: false,
	    		      type: "POST",
	    		      dataType: "json",
	    		      data: ({
	    		    	  outwhId : outwhId
	    		      }),		     
	    		      success: function(data){
	    		    	if(undefined != data && undefined != data.aclOutwh && null != data.aclOutwh){
	    		    		$("#zd003OutWhId").val(data.aclOutwh.zd003OutWhId);
	    		    		$("#zd003OutWhCode").val(data.aclOutwh.zd003OutWhCode);
	    		    		$("#zd003OutWhName").val(data.aclOutwh.zd003OutWhName);
	    		    		$("#zd004InWhId").val(data.aclOutwh.zd004InWhId);
	    					$("#zd004InWhCode").val(data.aclOutwh.zd004InWhCode);
	    					$("#zd004InWhName").val(data.aclOutwh.zd004InWhName);
	    					$("#zd005OutDate").val(formatDate(new Date(data.aclOutwh.zd005MoveDate),"yyyy-MM-dd"));
	    		    	}else{
	    		    		alert("返回对象为空");
	    		    	}
	    		      }
	    	   });
			}
			multipleSearch("#dataGrid1",true,"",basic_Url+"/aochItems.do?aochId="+outwhId);
		});
		
		$("#inputForm").validate({
			onsubmit : true,
			//执行ajaxsubmit  
			submitHandler : function(editform) {

				//alert(jsonInfo); 
				try {
					url = basic_Url + "/save.do";
					var api = frameElement.api;
					var W = api.opener;

					getReturnMessage(url, "inputForm", W.searchAP);
				} catch (e) {
					alert(e);
				}
			}
		}); 
		//按钮
	 	if(billSt=='' || '${flag}'=='ADD'){
			//新增
			$("#forExcel").hide();
			$("#forSubmit").hide();
			$("#forBack").hide();
			$("#forAudit").hide();
			$("#forAuditEnd").hide();
			$("#forApproved").hide();
		}else if(billSt=='INWH_SAVE'){
			//暂存
			$("#forExcel").hide();
			$("#forSave").hide();
			$("#forBack").hide();
			$("#forAudit").hide();
			$("#forAuditEnd").hide();
			$("#forApproved").hide();
		}else if(billSt=='INWH_SUBMIT'){
			//已提交待二审
			$("#forExcel").hide();
			$("#forSave").hide();
			$("#forSubmit").hide();
			$("#forApproved").hide();
		}else if(billSt=='INWH_AUDIT'){
			//已二审待三审
			$("#forExcel").hide();
			$("#forSave").hide();
			$("#forSubmit").hide();
			$("#forAudit").hide();
			$("#forAuditEnd").hide();
		}else if(billSt=='INWH_APPROVE'){
			//已三审
			$("#forExcel").hide();
			$("#forSave").hide();
			$("#forSubmit").hide();
			$("#forAudit").hide();
			$("#forAuditEnd").hide();
			$("#forBack").hide();
			$("#forApproved").hide();
		}else if(billSt=='INWH_BACK'){
			//已驳回
			$("#forExcel").hide();
			$("#forSave").hide();
			$("#forBack").hide();
			$("#forAudit").hide();
			$("#forAuditEnd").hide();
			$("#forApproved").hide();
		}else{
			
		}
	});
	function deleteRow(){
		addressGrid.deleteSelectedRow();
	}
	function submitForm(param) {
		var data = $("#dataGrid1").ligerGetGridManager().getData();
		if(data.length==0){
			$.dialog.alert("调拨内容不能为空");
	   	 	return false;
		}
		var ba=true;
		if(data !=null){ 
			for (var i = 0;i < data.length;i++){
				var row = data[i];
				if(parseFloat(row.zd019InQuantity) > parseFloat(row.zd021NoInQuantity)){
	           	 	$.dialog.alert("您第"+(i+1)+"行的本次接收入库数量大于未接收数量!!");
					ba = false;
					return false;
	            }
				if(parseFloat(row.zd019InQuantity) <= 0||row.zd019InQuantity==null){
		           	$.dialog.alert("您第"+(i+1)+"行的本次接收数量不合法!!");
					ba = false;
					return false;
		        }
			}
		}
		//设置ajax全局同步
		jQuery.ajaxSettings.async = false;
		if(ba){
			$("#dataItem").val(JSON.stringify(data));
			$("#flagMark").val(param);
			$("#inputForm").submit();
		}
	}	
	
	function close(){
		var api = frameElement.api;
		var W = api.opener;
		CloseDialog();
		W.searchAP();
	}
    
</script>
</head>
<body>
	<form id="inputForm" action="" method="post">
		<input type="hidden" id="id" name="id" value="${inwh.id}" />
		<input type="hidden" id="bizVersion" name="bizVersion" value="${inwh.bizVersion }" />
		<input type="hidden" id="dataItem" name="dataItem"/>
		<input type="hidden" id="datadele" name="datadele"/>
		<!-- 用于标识提交按钮 -->
		<input type="hidden" id="flagMark" name="flagMark" value="" />
		<div class="pageContent"  id="endDiv">
			<div class="panel">
				<table class="TableBlock" align="center">
				<c:if test="${!empty inwh.zd002InCode}">
					<tr >
						<td nowrap="nowrap" width="20%">调拨接收单号:</td>
						<td width="30%">
							<input id="zd002InCode" name="zd002InCode" readonly="readonly"  class="inp_width_98p" value="${inwh.zd002InCode}" /></td>
						<td nowrap="nowrap" width="20%">建单时间:</td>
						<td width="30%">
							<input class="inp_width_98p" type="text" id="bizCreatorDate" name="bizCreatorDate"
							value="<fmt:formatDate value="${empty inwh.bizCreatorDate?nowDate:inwh.bizCreatorDate}" type="both" dateStyle="long" pattern="yyyy-MM-dd" />" readonly="readonly"/>
						</td>
					</tr>
				</c:if>
				<tr>
					<td nowrap="nowrap" width="20%">调拨发起单号:</td> 
					<c:choose>
						<c:when test="${empty inwh.zd001AllocatCode}">
							<td width="30%">
								<select id="zd001AllocatId" name="zd001AllocatId" class="inp_width_98p required" >
									<option></option>
									<c:forEach items='${outwhList}' var='outwh'>
	   		                 			<option value='${outwh.id}' <c:if test="${inwh.zd001AllocatId eq outwh.id }">selected</c:if>>${outwh.zd001Code }</option>
	   		                 		</c:forEach>
								</select>
								<input type="hidden" id="zd001AllocatCode" name="zd001AllocatCode" value="${inwh.zd001AllocatCode }"/>
	   		             	</td>
	   		            </c:when>
	   		            <c:otherwise>
	   		             	<td>
	   		             		<input type="hidden" readonly="readonly" id="zd001AllocatId" class="inp_width_98p" name="zd001AllocatId" value="${inwh.zd001AllocatId}"/>
								<input type="text" readonly="readonly" id="zd001AllocatCode" class="inp_width_98p" name="zd001AllocatCode" value="${inwh.zd001AllocatCode}"/>
	   		             	</td> 
	   		            </c:otherwise>
   		         	</c:choose>
					<td nowrap="nowrap" width="20%">入库时间:</td>
					<td width="30%">
						<input id="zd005InDate" name="zd005InDate" class="inp_width_98p required" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"
							value="<fmt:formatDate value="${inwh.zd005InDate}" pattern="yyyy-MM-dd" type="both" />" />
						<c:if test="${inwh.zd005InDate == null}">
							<script>
								var date = new Date();
								$("#zd005InDate").val(date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate());
							</script>
						</c:if>
					</td>
				</tr>
				<tr>
					<td nowrap="nowrap" width="20%">送货仓:</td>
					<td width="30%">
						<input type="hidden" id="zd003OutWhId" name="zd003OutWhId" value="${inwh.zd003OutWhId }"/>
   		                <input type="hidden" id="zd003OutWhCode"  name="zd003OutWhCode" value="${inwh.zd003OutWhCode }"/>
   		             	<input type="text" id="zd003OutWhName" name="zd003OutWhName" value="${inwh.zd003OutWhName }" class="inp_width_98p required" readonly="readonly" />
   		            </td>
					<td nowrap="nowrap" width="20%">收货仓:</td>
					<td width="30%">
   		            	<input type="hidden" id="zd004InWhId" name="zd004InWhId" value="${inwh.zd004InWhId }"/>
   		                <input type="hidden" id="zd004InWhCode"  name="zd004InWhCode" value="${inwh.zd004InWhCode }"/>
   		             	<input type="text" id="zd004InWhName" name="zd004InWhName" value="${inwh.zd004InWhName }" class="inp_width_98p required" readonly="readonly" />
   		            </td>
				</tr>
				<tr>
					<td nowrap="nowrap" width="20%">发起日期:</td>
					<td width="30%">
						<input id="zd005OutDate" name="zd005OutDate" class="inp_width_98p required" readonly="readonly"  value="<fmt:formatDate value="${inwh.zd005OutDate }" pattern="yyyy-MM-dd" type="both" />" />
						<c:if test="${inwh.zd005OutDate == null}">
							<script>
								var date = new Date();
								$("#zd005OutDate").val(date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate());
							</script>
						</c:if>
					</td>
					<td nowrap="nowrap" width="20%">制单人:</td>
					<td width="30%">
						<input type="text" id="zd007Aegnt" name="zd007Aegnt" class="inp_width_98p" value="${inwh.bizCreatorName }" readonly="readonly" />
						<c:if test="${inwh.bizCreatorName == null}">
							<script>
								$("#bizCreatorName").val("${user.name}");
							</script>
						</c:if>
					</td>
				</tr>
				<tr>
					<td nowrap>备注:</td>
					<td colspan="3">
						<input id="zd008Remark" name="zd008Remark" class="inp_width_98p" value="${inwh.zd008Remark }" />
					</td>
				</tr>
				<tr>
					<td colspan="4" style="margin-bottom: 10px;">
						<div id="dataGrid1"></div>
					</td>
				</tr>
			</table>
		</div>
		<div class="formBar">
			<ul>
				<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="forSave" onclick="submitForm('INWH_SAVE')">保存</button></div></div></li>
				<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="forSubmit" onclick="submitForm('INWH_SUBMIT')">提交</button></div></div></li>
				<webres:displaycontroller elementId="LOGIC_TRSTART_JS_ZG" description="调拨接收单二级审核">
			       	<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="forAudit" onclick="submitForm('INWH_AUDIT')" title="提交二级审核">二级审核</button></div></div></li>
		       	</webres:displaycontroller>
				<webres:displaycontroller elementId="LOGIC_TRSTART_JS_WJ" description="调拨接收单二审完结">
			       	<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="forAuditEnd" onclick="submitForm('INWH_APPROVE')">二审完结</button></div></div></li>
		       	</webres:displaycontroller>
		        <webres:displaycontroller elementId="LOGIC_TRSTART_JS_JL" description="调拨接收单三审完结">
			       	<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="forApproved" onclick="submitForm('INWH_APPROVE')">三审完结</button></div></div></li>
		       	</webres:displaycontroller>
		       	<webres:displaycontroller elementId="LOGIC_TRSTART_JS_BH" description="调拨接收单驳回">
		       		<li><div class="buttonActive"><div class="buttonContent"><button type="button" id="forBack" onclick="submitForm('INWH_BACK')">驳回</button></div></div></li>
		       	</webres:displaycontroller>
		       	<li><div class="button"><div class="buttonContent"><button type="button" class="print" onclick="CloseDialog()">关闭</button></div></div></li>
			</ul>
		</div>
		</div>
	</form>
</body>
</html>
